#include "StdAfx.h"
#include "RemotePlayer.h"



Piece * RemotePlayer::choosePiece(std::vector<Piece> & pieces, char piece[4])
{
	// Black/Red, Small/Big, Flat/Hole, Round/Square
	unsigned char trait = ((piece[0]!='0') << (3)) | ((piece[1] == '0') << (2)) | ((piece[3] == '0') << (1)) | (piece[2] == '0');
	for(int i = 0; i < pieces.size(); ++i)
	{
		if(trait == pieces[i].getTrait()) return &pieces[i];
	}
	return NULL;
}

Piece * RemotePlayer::play(Piece * currentPiece, std::vector<Piece> & pieces, char move[9])
{
	currentPiece->setLocation(std::make_pair((unsigned char) move[0]-'0', (unsigned char) move[3]-'0'));
	char piece[4];
	piece[0] = move[5];
	piece[1] = move[6];
	piece[2] = move[7];
	piece[3] = move[8];
	return choosePiece(pieces,piece);
}
